﻿package com.game.module.gameTask.vo
{
	import config.Config;
	
	public class TaskVO
	{
		
		public function TaskVO(taskId:uint, taskName:String, description:String, needMonster:Array, allReward:Array)
		{
			this.rwaward = [];
			super();
			this.taskId = taskId;
			this.taskName = taskName;
			this.description = description;
			this.needKillMonster = needMonster;
			this.allReward = allReward;
		}
		
		public var rwaward:Array;
		public var allReward:Array;
		public var taskId:uint;
		public var taskName:String;
		public var description:String;
		public var needKillMonster:Array;
		public var isComplete:Boolean = false;
		public var hasGetAward:Boolean = false;
		
		public function getrwId():uint
		{
			return this.taskId;
		}
		
		public function getrwname():String
		{
			return this.taskName;
		}
		
		public function getrwdict():String
		{
			return this.description;
		}
		
		public function setHasGetAward(param1:Boolean):void
		{
			this.hasGetAward = param1;
		}
		
		public function getHasGetAward():Boolean
		{
			return this.hasGetAward;
		}
		
		public function getAllAward():Array
		{
			return this.allReward;
		}
		
		public function getTaskPro():String
		{
			var _loc1_:String = "";
			var _loc2_:uint = this.needKillMonster.length;
			var _loc3_:int = 0;
			while (_loc3_ < _loc2_)
			{
				_loc1_ += this.needKillMonster[_loc3_].name + " " + this.needKillMonster[_loc3_].curhas + "/" + this.needKillMonster[_loc3_].neednum + "  ";
				_loc3_++;
			}
			return _loc1_;
		}
		
		public function judgeNeed(param1:String):Boolean
		{
			var _loc2_:uint = this.needKillMonster.length;
			var _loc3_:int = 0;
			while (_loc3_ < _loc2_)
			{
				if (this.needKillMonster[_loc3_].mname == param1)
				{
					if (this.needKillMonster[_loc3_].curhas < this.needKillMonster[_loc3_].neednum)
					{
						++this.needKillMonster[_loc3_].curhas;
						return true;
					}
				}
				_loc3_++;
			}
			this.judgeComplete();
			return false;
		}
		
		public function hasChangeTask():Boolean
		{
			var _loc1_:uint = this.needKillMonster.length;
			var _loc2_:int = 0;
			while (_loc2_ < _loc1_)
			{
				if (this.needKillMonster[_loc2_].curhas > 0)
				{
					return true;
				}
				_loc2_++;
			}
			return false;
		}
		
		public function judgeComplete():Boolean
		{
			if (this.taskId > 100)
			{
				return this.judgeAtask(this.taskId);
			}
			else
			{
				var _loc1_:uint = this.needKillMonster.length;
				while (_loc1_-- > 0)
				{
					if (this.needKillMonster[_loc1_].curhas < this.needKillMonster[_loc1_].neednum)
					{
						return false;
					}
				}
				this.isComplete = true;
				return true;
			}
		}
		
		public function getSave():String
		{
			var _loc1_:uint = this.needKillMonster.length;
			var _loc2_:* = this.taskId + "";
			var _loc3_:int = 0;
			while (_loc3_ < _loc1_)
			{
				_loc2_ += "|" + this.needKillMonster[_loc3_].curhas;
				_loc3_++;
			}
			return _loc2_ + ("|" + this.isComplete + "|" + this.hasGetAward);
		}
		
		public function setSave(param1:String):Boolean
		{
			var _loc4_:Array = null;
			var _loc2_:* = 0;
			var _loc3_:int = 0;
			if ((_loc4_ = param1.split("|"))[0] == this.taskId)
			{
				_loc2_ = uint(this.needKillMonster.length);
				_loc3_ = 0;
				while (_loc3_ < _loc2_)
				{
					this.needKillMonster[_loc3_].curhas = _loc4_[_loc3_ + 1];
					_loc3_++;
				}
				this.isComplete = _loc4_[_loc2_ + 1];
				if (_loc4_[_loc2_ + 2] == true || _loc4_[_loc2_ + 2] == "true")
				{
					this.hasGetAward = true;
				}
				else
				{
					this.hasGetAward = false;
				}
				return true;
			}
			return false;
		}
		
		private function judgeAtask(param1:int):Boolean
		{
			switch (param1 - 100)
			{
				case 1:
					if (Config.getIns().playerData.getEquipInBagByName("tjbg"))
					{
						return !this.hasGetAward;
					}
					return false;
				case 2:
					return !this.hasGetAward;
				default:
					return false;
			}
		}
	}
}
